package com.xcity.pomelo.response;

import java.util.Collections;
import java.util.List;

import com.xcity.db.entity.Mine;
import com.xcity.game.map.Locatable;
import com.xcity.game.map.MapService;

import naga.x.game.time.TimeUpdater;
import naga.x.net.impl.pomelo.PomeloMessage;
import naga.x.net.impl.pomelo.protocol.Message;

@PomeloMessage(type = Message.Type.RESPONSE)
public class MapResponse extends Response {
	
	protected int mapX, mapY;
	protected List<Locatable> list;
	private List<MineInfo> mineList;
	
	public static class MineInfo{
		public int id;
		public int map;
		public int pos;
		public int posX;
		public int posY;
		public int mineType;
		public long ownerId;
		public String name;
		public String ownerIcon;
		
		public MineInfo(Mine mine, int[] pos){
			this.id = mine.getId();
			this.mineType = mine.getMineType();
			this.map = mine.getMap();
			this.pos = mine.getPos();
			this.posX = pos[0];
			this.posY = pos[1];
			
			this.ownerId = mine.getOwnerId();
			this.name = mine.getOwnerName();
			this.ownerIcon = mine.getOwnerIcon();
		}
	}
	
	public static class MineSelfInfo{
		public int mapX;
		public int mapY;
		public int mineId;
		public int map;
		public int pos;
		public int mineType;
		public int leftSecond;
		public MineSelfInfo(Mine mine, int[] mapXY){
			mapX = mapXY[0];
			mapY = mapXY[1];
			mineId = mine.getId();
			map = mine.getMap();
			pos = mine.getPos();
			mineType = mine.getMineType();
			leftSecond = (int) ((mine.getTakeTime() + (mine.getExtendCount()) * MapService.TAKE_MAX_DURATION - TimeUpdater.getInstance().now()) / 1000L);
			if(leftSecond < 0){
				leftSecond = 0;
			}
		}
	}

	public MapResponse(int serial) {
		this(serial, -1, -1, Collections.emptyList(), Collections.emptyList());
	}
	
	public MapResponse(int serial, int mapX, int mapY, List<Locatable> units, List<MineInfo> mineList) {
		super(serial);
		this.mapX = mapX;
		this.mapY = mapY;
		this.list = units;
		this.mineList = mineList;
	}

	public int getMapX() {
		return mapX;
	}

	public void setMapX(int mapX) {
		this.mapX = mapX;
	}

	public int getMapY() {
		return mapY;
	}

	public void setMapY(int mapY) {
		this.mapY = mapY;
	}

	public List<Locatable> getList() {
		return list;
	}

	public void setList(List<Locatable> list) {
		this.list = list;
	}

	public List<MineInfo> getMineList() {
		return mineList;
	}

	public void setMineList(List<MineInfo> mineList) {
		this.mineList = mineList;
	}
}
